package blackhouse_servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import blackhouse_server.change_teacherinfo_server;
import blackhouse_server.teacher_info_server;

import com.alibaba.fastjson.JSON;

@WebServlet("/teacherinfo")
public class teacher_info_servlet extends HttpServlet
{
	teacher_info_server	TS	= new teacher_info_server();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		PrintWriter print = resp.getWriter();
		String code = req.getParameter("code");
		String key = req.getParameter("key");
		String json = null;
		try
		{
			if (code.equals("1"))
			{
				boolean isok = TS.deltinfo(key);
				print.write(isok + "");
			} else if (code.equals("2"))
			{
				String id = req.getParameter("ID");
				json = JSON.toJSONString(TS.seektinfo(id));
				print.write(json);
			} else if (code.equals("4"))
			{
				change_teacherinfo_server cts = new change_teacherinfo_server();
				int tage = Integer.parseInt(req.getParameter("tage"));
				String ID = req.getParameter("tCode");
				String tgoodat = req.getParameter("tgoodat");
				String tPhone = req.getParameter("tPhone");
				String tQQ = req.getParameter("tQQ");
				String temail = req.getParameter("temail");
				String taddress = req.getParameter("taddress");
				boolean isok = cts.chanfetinfo(ID, tage, tgoodat, tPhone, tQQ,
						temail, taddress);
				print.write(isok + "");
			} else
			{
				json = JSON.toJSONString(TS.showtinfo(code, key));
				print.write(json);
			}
		} catch (SQLException e)
		{

			e.printStackTrace();
		}

	}
}
